package com.masterclient.app.modules.goods.widget;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.eoner.baselibrary.utils.ScreenUtils;
import com.masterclient.app.R;

public class PurchaseDialog extends Dialog{

    public PurchaseDialog(@NonNull Context context,OnChooseListener onChooseListener) {
        super(context, R.style.MyDialog);
        this.onChooseListener = onChooseListener;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_purchases);
        TextView tv_cancel = findViewById(R.id.tv_cancel);
        TextView tv_confirm = findViewById(R.id.tv_confirm);

        tv_cancel.setOnClickListener(v->{
            if(onChooseListener!=null){
                onChooseListener.cancel();
            }
        });
        tv_confirm.setOnClickListener(v->{
            if(onChooseListener!=null){
                onChooseListener.confirm();
            }
        });

    }

    @Override
    protected void onStart() {
        super.onStart();
        Window window = getWindow();
        WindowManager.LayoutParams windowparams = window.getAttributes();
        windowparams.width = ScreenUtils.getScreenWidth();
        window.setGravity(Gravity.CENTER);
        window.setBackgroundDrawableResource(android.R.color.transparent);
        window.setAttributes(windowparams);
    }

    public void setOnChooseListener(OnChooseListener onChooseListener) {
        this.onChooseListener = onChooseListener;
    }

    private OnChooseListener onChooseListener;

    public interface OnChooseListener{
        void cancel();
        void confirm();
    }
}
